#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int main(int argc, char const *argv[])
{
    char buf[1024];
    int fd = open("/etc/profile", O_RDONLY);
    if (fd < 0)
    {
        printf("open failed");
        perror("open");
        return 1;
    }

    ssize_t read_len = read(fd, buf, 1024);
    printf("读了%ld\n", read_len);

    ssize_t write_len = write(STDOUT_FILENO, buf, read_len);
    printf("写了%ld\n", write_len);

    close(fd);
    return 0;
}
